#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
    int days;
    cin >> days;
    int book;
    char op;
    int hour;
    int minute;
    char skip;
    int start[1001];

    for(int i = 0; i< days; i++)
    {
        int times = 0;
        int time = 0;
        for(int i = 0; i<1001; i++)
            start[i] = -1;

        while(true)
        {
            cin >> book >> op >> hour >>  skip >> minute;
            //cout << book << op << hour << minute << endl;
            if(book == 0) 
            {
                int ave = round(time == 0 ? 0 : time/(float)times);
                cout << times << " " << ave << endl;
                break;
            }
            if( op == 'S')
            {
                int stime =  hour * 60 + minute;
                start[book] = stime;
              
            }
            if(op == 'E') 
            {
                    int etime =  hour * 60 + minute;
                    if(start[book] >= 0)
                    {
                        times = times + 1;
                        time = time + (etime - start[book]);
                        start[book] = -1;  
                    }
                 
            }
        }
    }
  
}